<template>
  <div class="current-page">
    <div>
      <!-- <el-button
        style="margin-bottom: 10px; float: left; padding-right: 20px"
        type="primary"
      >
        高级搜索
      </el-button> -->
      <div class="search-btn">
        <el-button style="margin-bottom: 10px; float: right; padding-right: 20px" type="text" icon="el-icon-refresh"
          @click="refreshTable">刷新
        </el-button>
        <!-- <el-button
          style="margin-bottom: 10px; float: right; padding-right: 20px"
          type="text"
          @click="exprotData"
          icon="el-icon-download"
          >导出
        </el-button> -->
      </div>
    </div>
    <com-table :tableData="tableData" url="sjrz/log/udiskuse" keyName="LogDiskUse" :has-data="hasData" method="get"
      :table-head-list="tableHeadList" :total-count="totalCount" :page-num="pageNum" :page-size="pageSize"
      :page-sizes="pageSizes" :table-loading="loading" :table-height="tableHeight" :is-show-select="false"
      :page-show="true" :handle-show="false" :merge-flag="false" @setSearchHeight="setSearchHeight"
      @openDialog="openDialog" @getTabpation="getTabpation" ref="comTable">
    </com-table>
    <el-dialog :title="dialogTitle" :visible.sync="dialogControl" width="40%" @close="dialogControl = false"
      :close-on-click-modal="false" :close-on-press-escape="false"
      custom-class="strategy-dialog equip-detail el-dialog-widthSmall" v-dialogDrag @closed="dialogClosed">
      <el-form ref="infoForm" :model="infoForm" label-width="150px" :rules="rules">
        <el-row>
          <el-col :span="18">
            <el-form-item label="应用标识" prop="uuid">
              <el-input v-model.trim="infoForm.uuid" placeholder="请输入标识" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="应用名称" prop="name">
              <el-input v-model.trim="infoForm.name" placeholder="请输入名称" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="应用ip" prop="ip">
              <el-input v-model.trim="infoForm.ip" placeholder="请输入ip" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="应用端口" prop="port">
              <el-input v-model.trim="infoForm.port" placeholder="请输入端口" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="应用类别">
              <el-select v-model="infoForm.type" placeholder="请选择">
                <el-option v-for="item in attrData" :key="item.XPRO_PATH" :label="item.content" :value="item.XPRO_PATH">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogControl = false">取 消</el-button>
        <el-button v-if="dialogTitle == '新增应用资源'" type="primary" @click="addTerminal">确 定</el-button>
        <el-button v-if="dialogTitle == '修改应用资源'" type="primary" @click="modifyTerminal">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="dialogConemit" width="60%" @close="dialogConemit = false" :close-on-click-modal="false"
      :close-on-press-escape="false" custom-class="strategy-dialog equip-detail el-dialog-widthSmall" v-dialogDrag
      @closed="dialogcdClosed">
      <el-form ref="infoemdForm" :model="infoemdForm" label-width="90px">
        <el-row style="width: 66%; margin: 0 auto">
          <el-tabs v-model="activeName" type="card">
            <el-tab-pane label="U盘登录" name="first">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="责任人">
                    <el-input v-model.trim="infoemdForm.vid" placeholder="请输入责任人" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="密级">
                    <el-input v-model.trim="infoemdForm.vid" placeholder="请输入密级" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="密码">
                    <el-input v-model.trim="infoemdForm.vid1" placeholder="请输入密码" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="text-align: center">
                <el-checkbox v-model="checkuped">格式化U盘</el-checkbox>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="修改" name="second">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="原始密码">
                    <el-input v-model.trim="infoemdForm.pid" placeholder="请输入原始密码" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="新密码">
                    <el-input v-model.trim="infoemdForm.vid" placeholder="请输入新密码" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="确认密码">
                    <el-input v-model.trim="infoemdForm.vid1" placeholder="请输入确认密码" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <p>密码长度为8~16位，且必须为数字、大小写字母或符号至少2种</p>
            </el-tab-pane>
          </el-tabs>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogConemit = false">取 消</el-button>
        <el-button type="primary" v-show="activeName == 'first'" @click="confirmInfo">登 录</el-button>
        <el-button type="primary" v-show="activeName == 'second'" @click="modifclis">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import ComTable from "../../components/table/comTable";
export default {
  name: "ReddiskAccessLog",
  data() {
    return {
      pageSizes: [5, 10, 20, 50, 100],
      hasData: true,
      dialogControl: false,
      dialogTitle: "",
      tableHeadList: [
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "登录用户",
          columnName: "LoginUser",
        },
        {
          colDisabled: false,
          colHidden: true,
          colSearch: true,
          colSort: false,
          columnComment: "部门",
          columnName: "DeptName",
        },
        {
          colDisabled: false,
          colHidden: true,
          colSearch: true,
          colSort: false,
          columnComment: "责任人",
          columnName: "EmpName",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "序列号",
          columnName: "USN",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "操作时间",
          columnName: "OpTime",
        },

        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "厂商ID",
          columnName: "UVid",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "产品ID",
          columnName: "UPid",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "优盘单位",
          columnName: "UUnitName",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "优盘责任人",
          columnName: "UUser",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "优盘密级",
          columnName: "USecLevel",
        },
        {
          colDisabled: false,
          colHidden: false,
          colSearch: true,
          colSort: false,
          columnComment: "描述",
          columnName: "Content",
        },
      ],
      pageNum: 1,
      pageSize: 10,
      totalCount: 0,
      boolean: [],
      tableData: [], // 表格数据
      tableHeight: "", // 表格高度
      loading: false, // 数据加载状态遮罩
      checkuped: true,
      tableDataSelected: [],
      operateTime: [],
      xproPath: "",
      searchForm: {
        warnState: "",
        warnRank: "",
        warnContent: "",
        objType: "",
      },
      infoForm: {
        from: "本地",
      },
      infoemdForm: {},
      attrData: [],
      rules: {
        // 表单验证规则
        name: [{ required: true, trigger: "blur", message: "请输入名称" }],
      },
      emwCheckList: [],
      dialogConemit: false,
      activeName: "",
    };
  },
  components: {
    ComTable,
  },
  created() {
    this.setTableHeight();
    this.getTableData(this.pageNum, this.pageSize);
    // this.getattrDataList(this.pageNum, this.pageSize)
  },
  methods: {
    confirmInfo() {
      let data = {
        msg_type: "UDISK_LOGIN",
        content: {
          passwd: this.infoemdForm.vid,
          dev_info: "0508931812-aaaa-0008",
          format: 1,
        },
      };
      this.$post("3in1/config/rdisknoticelogin", data).then((res) => {
        console.log(res);
      });
    },
    modifclis() {
      if (this.infoemdForm.vid != this.infoemdForm.vid1) {
        this.$message({
          message: "密码不一致",
          type: "warning",
        });
        return;
      }
      let data = {
        msg_type: "CHANGE_PASSWD",
        content: {
          new_password: "222222",
          old_password: "111111",
          dev_info: "0508931812-aaaa-0008",
        },
      };
      this.$post("3in1/config/rdisknoticechange", data).then((res) => {
        console.log(res);
      });
    },
    dialogcdClosed() { },
    refreshTable() {
      this.pageNum = 1
      this.pageSize = 10
      if (this.hasData) {
        this.getTableData(this.pageNum, this.pageSize);
      } else {
        // 调用子组件中的getTableData
        this.$refs.comTable.getTableData();
      }
    },
    getTableData(pageNum, pageSize) {
      this.$get(`sjrz/log/udiskuse?page=0&count=0`).then((res) => {
        console.log(res);
        let uDiskDatas = []
        res.data.data.forEach((item) => {
          uDiskDatas.push(item.Root.LogDiskUse);
        })
        this.totalCount = uDiskDatas.length
        this.$get(`sjrz/log/udiskuse?page=${pageNum}&count=${pageSize}`).then((res1) => {
          console.log(res1);
          let uDiskDatas1 = []
          res1.data.data.forEach((item) => {
            uDiskDatas1.push(item.Root.LogDiskUse);
          })
          this.tableData = uDiskDatas1
        });

      });
    },
    getTableData1(pageNum, pageSize) {
      this.$get(`sjrz/log/udiskuse?page=${pageNum}&count=${pageSize}`).then((res) => {
        console.log(res);
        let uDiskDatas = []
        res.data.data.forEach((item) => {
          uDiskDatas.push(item.Root.LogDiskUse);
        })
        this.tableData = uDiskDatas
      });
    },
    getTabpation(pageNum, pageSize) {
      console.log(pageNum, pageSize)
      this.getTableData1(pageNum, pageSize)
    },
    //重新加载表格
    setSearchHeight() {
      //搜索区域高度
      if (this.$refs.search !== undefined) {
        this.$nextTick(() => {
          let searchHeight = this.$refs.search.offsetHeight;
          this.setTableHeight(searchHeight);
        });
      }
    },
    //关闭表单
    dialogClosed() {
      this.infoForm = {
        name: "",
        ip: "",
        port: "",
        type: [],
        from: "本地",
      };
    },

    /**
     * 设置表格的高度
     */
    setTableHeight() {
      let clientHeiht =
        window.innerHeight || document.documentElement.clientHeight;
      this.tableHeight = clientHeiht - 160;
    },
    headerCellStyle({ row, column, rowIndex, columnIndex }) {
      return {
        "font-size": "14px",
        "font-weight": 600,
        color: "#606266",
      };
    },
    //查询
    //todo 待后台接口
    search() { },

    //新建与修改
    openDialog(type, row) {
      this.dialogControl = true;
      console.log(type);
      if (type === "add") {
        this.dialogTitle = "新增应用资源";
      } else if (type === "update") {
        this.dialogTitle = "修改应用资源";
        console.log(row, "row");
        let form = JSON.parse(JSON.stringify(row));
        console.log(form, "qqqq");
        (this.xproPath = form.XPRO_PATH),
          (this.infoForm = {
            name: form.name,
            uuid: form.uuid,
            ip: form.ip,
            port: form.port,
            type: [],
            from: "本地",
          });
        if (form.type.length > 0) {
          form.type.forEach((item) => {
            this.infoForm.type = item.XPRO_PATH;
          });
        }
      }
    },

    /**
     * 新增
     */
    addTerminal() {
      this.$refs.infoForm.validate((flag) => {
        if (flag) {
          let params = {};
          for (let item in this.infoForm) {
            if (this.infoForm[item]) {
              if (item == "type") {
                if (this.infoForm[item].length !== 0) {
                  console.log(item, this.infoForm[item], "item789");
                  params[item] = [this.infoForm[item]];
                }
              } else {
                params[item] = this.infoForm[item];
              }
            }
          }
          console.log(params);
          this.loading = true;
          this.$postForJson("app", params).then((jsonData) => {
            this.dialogControl = false;
            this.loading = false;
            let datas = jsonData.data;
            if (!datas.success) {
              this.publicModal.$emit("tips", {
                show: true,
                publicModalMessage: datas.msg,
                fontIcon: "errorWarning",
              });
              return false;
            }
            this.$message({
              message: "新增文本文件信息成功！",
              type: "success",
            });
            this.refreshTable();
            this.dialogClosed();
          });
        }
      });
    },

    /**
     * 修改
     */
    modifyTerminal() {
      this.$refs.infoForm.validate((flag) => {
        if (flag) {
          let params = {};
          for (let item in this.infoForm) {
            if (this.infoForm[item]) {
              if (item == "type") {
                if (this.infoForm[item].length !== 0) {
                  console.log(item, this.infoForm[item], "item789");
                  params[item] = [this.infoForm[item]];
                }
              } else {
                params[item] = this.infoForm[item];
              }
            }
          }
          let url = this.xproPath;
          this.loading = true;
          console.log(params, "params");
          this.$postForJson(url, params).then((jsonData) => {
            this.dialogControl = false;
            this.loading = false;
            let datas = jsonData.data;
            if (!datas.success) {
              this.publicModal.$emit("tips", {
                show: true,
                publicModalMessage: datas.msg,
                fontIcon: "errorWarning",
              });
              return false;
            }
            this.$message({
              message: "修改文本文件信息成功",
              type: "success",
            });
            this.refreshTable();
            this.dialogClosed();
          });
        }
      });
    },
    //重置
    clearData() {
      this.searchForm = {};
    },
    exprotData() { },
  },
};
</script>
<style scoped>
@import "../../assets/css/treeAndTable.css";
@import "../../assets/css/commonTable";

.view {
  position: relative;
  left: 190px;
}

.title-left {
  display: inline-block;
  font-weight: 600;
  margin-left: 20px;
  margin-top: 7px;
}

.right {
  float: right;
  margin-right: 20px;
}

.block {
  text-align: center;
  margin-right: 20px;
  margin-top: 10px;
}

.checkTitle {
  width: 164px;
  height: 16px;
}

.importOrgInfo {
  cursor: pointer;
  color: #101fec;
  text-decoration: underline;
}

.importBody {
  display: flex;
  align-items: center;
  flex-grow: 1;
}

.seamless-warp {
  height: 250px;
  overflow: hidden;
}

.importIcon {
  font-size: 52px;
  width: 90px;
  text-align: center;
}

.new-search-area .btn-area .el-button {
  margin-bottom: 10px;
}

.hstyle {
  color: lightskyblue;
  margin: 10px;
  border-bottom: 1px solid #999;
}

.pstyle {
  margin-left: 25px;
  cursor: pointer;
}

.rightStyle {
  /* padding-left: 5px; */
  border: 1px solid rgb(235, 238, 245);
  border-radius: 5px;
}

ul {
  padding-inline-start: 25px;
}

ul li {
  list-style-type: none;
  line-height: 25px;
  font-size: 15px;
}

ul li:hover {
  color: lightskyblue;
  cursor: pointer;
}

.active {
  color: lightskyblue;
}

.butt {
  margin-left: 116px !important;
  margin-top: 22px;
  margin-bottom: 20px;
}

.page {
  position: absolute;
  bottom: 63px;
  left: 900px;
}
</style>
